﻿using iLib.DataAccess;

namespace Cms.Utilities.DatabaseUpdaters
{
    internal class AccessUpdater : DatabaseUpdater
    {
        internal AccessUpdater(string connectionString)
        {
            Dam = new OleDbManager(connectionString);
        }

        private AccessUpdater()
        {
        }

        public override void Patch_0_9_12325_471()
        {
        }

        public override void Patch_0_9_12310_469()
        {
        }

        public override void Patch_0_9_12309_468()
        {
        }

        public override void Patch_0_9_12309_464()
        {
        }

        public override void Patch_0_9_12303_463()
        {
        }

        public override void Patch_0_9_12297_462()
        {
        }

        public override void Patch_0_9_12256_457()
        {
        }

        public override void Patch_0_9_12216_454()
        {
        }

        public override void Patch_0_9_12165_446()
        {
        }

        public override void Patch_0_9_12141_437()
        {
        }

        public override void Patch_0_9_12114_419()
        {
        }

        public override void Patch_0_9_12078_398()
        {
        }

        public override void Patch_0_9_12073_394()
        {
        }

        public override void Patch_0_9_12052_387()
        {
        }

        public override void Patch_0_9_12026_376()
        {
        }

        public override void Patch_0_9_12021_372()
        {
        }

        public override void Patch_0_9_12016_369()
        {
        }

        public override void Patch_0_9_11229_341()
        {
        }

        public override void Patch_0_9_11227_337()
        {
        }

        public override void Patch_0_9_11170_327()
        {
        }

        public override void Patch_0_9_11163_317()
        {
        }

        public override void Patch_0_9_11139_313()
        {
        }

        public override void Patch_0_9_11137_306()
        {
        }

        public override void Patch_0_9_11133_300()
        {
        }

        public override void Patch_0_9_11095_265()
        {
        }

        public override void Patch_0_9_11095_264()
        {
        }

        public override void Patch_0_9_11095_262()
        {
        }

        public override void Patch_0_9_11064_247()
        {
        }

        public override void Patch_0_9_10243_211()
        {
        }

        public override void Patch_0_9_10237_191()
        {
        }

        public override void Patch_0_9_10237_184()
        {
            Dam.ExecuteQuery(
                "ALTER TABLE [fpDetailTemplates] ADD COLUMN [DefaultMasterTemplateID] [int] NULL CONSTRAINT FK_fpDetailTemplates_DefaultMasterTemplateID REFERENCES fpMasterTemplates (ID)");
        }

        public override void Patch_0_9_10232_183()
        {
            Dam.ExecuteQuery("ALTER TABLE [fpAdministrators] ADD COLUMN [ShowIntroHelp] YESNO NOT NULL DEFAULT YES");
        }

        public override void Patch_0_9_10232_182()
        {
            Dam.ExecuteQuery("ALTER TABLE [fpAdministrators] ADD COLUMN [SerializedSearchContentSettings] MEMO NULL");
        }

        public override void Patch_0_9_10229_157()
        {
            Dam.ExecuteQuery("ALTER TABLE [fpMenus] ADD COLUMN [ActiveItemPrefix] TEXT(255) NULL");
        }

        public override void Patch_0_8_10228_130()
        {
            Dam.ExecuteQuery(
                "ALTER TABLE [fpMenuItemTranslations] ADD COLUMN [DefaultImageID] [int] NULL CONSTRAINT FK_fpMenuItemTranslations_DefaultImageID REFERENCES fpMediaFiles (ID)");
        }

        public override void Patch_0_8_10182_123()
        {
            Dam.ExecuteQuery("CREATE TABLE [fpMenus] (" +
                              "[ID] COUNTER NOT NULL PRIMARY KEY, " +
                              "[Name] TEXT(255) NOT NULL, " +
                              "[Description] MEMO NULL, " +
                              "[SiteID] INTEGER NOT NULL CONSTRAINT FK_fpMenus_SiteID REFERENCES fpSites (ID), " +
                              "[SourceCodeID] INTEGER NOT NULL CONSTRAINT FK_fpMenus_SourceCodeID REFERENCES fpSourceCode (ID), " +
                              "[ItemIsActiveWhenSubItemIsActive] YESNO NOT NULL DEFAULT YES, " +
                              "[SubMenuBehaviour] TEXT(30) NOT NULL DEFAULT 'Toggle'" +
                              ")");
            Dam.ExecuteQuery("CREATE TABLE [fpMenuVersions] (" +
                              "[ID] COUNTER NOT NULL PRIMARY KEY, " +
                              "[Timestamp] TEXT(255) NOT NULL, " +
                              "[MenuID] INTEGER NOT NULL CONSTRAINT FK_fpMenuVersions_MenuID REFERENCES fpMenus (ID), " +
                              "[EditedByAdministratorID] INTEGER NOT NULL CONSTRAINT FK_fpMenuVersions_EditedByAdministratorID REFERENCES fpAdministrators (ID)" +
                              ")");
            Dam.ExecuteQuery(
                "ALTER TABLE [fpMenus] ADD COLUMN [PublishedVersionID] INTEGER NULL CONSTRAINT FK_fpMenus_PublishedVersionID REFERENCES fpMenuVersions (ID)");
            Dam.ExecuteQuery("CREATE TABLE [fpMenuItems] (" +
                              "[ID] COUNTER NOT NULL PRIMARY KEY, " +
                              "[MenuVersionID] INTEGER NOT NULL CONSTRAINT FK_fpMenuItems_MenuVersionID REFERENCES fpMenuVersions (ID), " +
                              "[ParentID] INTEGER NULL CONSTRAINT FK_fpMenuItems_ParentID REFERENCES fpMenuItems (ID), " +
                              "[StartPublishing] DATETIME NULL, " +
                              "[EndPublishing] DATETIME NULL, " +
                              "[SortIndex] INTEGER NOT NULL, " +
                              "[LinkType] TEXT(20) NOT NULL, " +
                              "[Target] TEXT(20) NULL, " +
                              "[PageID] INTEGER NULL CONSTRAINT FK_fpMenuItems_PageID REFERENCES fpPages (ID), " +
                              "[MediaFileID] INTEGER NULL CONSTRAINT FK_fpMenuItems_MediaFileID REFERENCES fpMediaFiles (ID)" +
                              ")");
            Dam.ExecuteQuery("CREATE TABLE [fpMenuItemTranslations] (" +
                              "[MenuItemID] INTEGER NOT NULL CONSTRAINT FK_fpMenuItemTranslations_MenuItemID REFERENCES fpMenuItems (ID), " +
                              "[LocaleID] INTEGER NOT NULL CONSTRAINT FK_fpMenuItemTranslations_LocaleID REFERENCES fpLocales (ID), " +
                              "[Name] TEXT(255) NOT NULL, " +
                              "[Url] MEMO NULL, " +
                              "CONSTRAINT PK_fpMenuItemTranslations PRIMARY KEY (MenuItemID, LocaleID)" +
                              ")");
            Dam.ExecuteQuery("ALTER TABLE [fpAdministrators] ADD COLUMN [SelectedFolderID] INTEGER NOT NULL DEFAULT -1");
            Dam.ExecuteQuery(
                "ALTER TABLE [fpAdministrators] ADD COLUMN [SelectedMediaFolderID] INTEGER NOT NULL DEFAULT -1");
        }

        public override void Patch_0_7_10180_115()
        {
            Dam.ExecuteQuery("ALTER TABLE [fpVisitedAdminUrls] ALTER COLUMN [Url] MEMO NOT NULL");
        }

        public override void Patch_0_7_10175_107()
        {
            Dam.ExecuteQuery("ALTER TABLE [fpPageLocalizedProperties] ADD COLUMN [Description] MEMO NULL");
            Dam.ExecuteQuery("ALTER TABLE [fpPageLocalizedProperties] ADD COLUMN [Keywords] MEMO NULL");
        }

        public override void Patch_0_7_10175_105()
        {
        }

        public override void Patch_0_7_10175_104()
        {
            Dam.ExecuteQuery("ALTER TABLE [fpAdministrators] ADD COLUMN [DateFormat] TEXT(20) NULL");
            Dam.ExecuteQuery("ALTER TABLE [fpAdministrators] ADD COLUMN [TimeFormat] TEXT(20) NULL");
        }

        public override void Patch_0_7_10175_103()
        {
            string sql = "CREATE TABLE [fpPageLocalizedProperties] (" +
                         "[PageID] INTEGER NOT NULL CONSTRAINT FK_fpPageLocalizedProperties_PageID REFERENCES fpPages (ID), " +
                         "[LocaleID] INTEGER NOT NULL CONSTRAINT FK_fpPageLocalizedProperties_LocaleID REFERENCES fpLocales (ID), " +
                         "[Title] TEXT(255) NULL, " +
                         "CONSTRAINT PK_fpPageLocalizedProperties PRIMARY KEY (PageID, LocaleID)" +
                         ")";
            Dam.ExecuteQuery(sql);
        }

        public override void Patch_0_7_10173_95()
        {
            string sql = "ALTER TABLE fpPages ADD COLUMN [SortKey] TEXT(255) NULL";
            Dam.ExecuteQuery(sql);
            sql = "ALTER TABLE fpPages ALTER COLUMN [HeadHtml] MEMO NULL";
            Dam.ExecuteQuery(sql);
            sql = "ALTER TABLE fpPages ALTER COLUMN [BodyTopHtml] MEMO NULL";
            Dam.ExecuteQuery(sql);
            sql = "ALTER TABLE fpPages ALTER COLUMN [BodyBottomHtml] MEMO NULL";
            Dam.ExecuteQuery(sql);
        }

        public override void Patch_0_7_10172_94()
        {
            string sql = "CREATE TABLE fpPageCategories (" +
                         "[ID] COUNTER NOT NULL PRIMARY KEY, " +
                         "[Name] TEXT(255) NOT NULL, " +
                         "[SiteID] INTEGER NOT NULL CONSTRAINT FK_fpPageCategories_SiteID REFERENCES fpSites (ID)" +
                         ")";
            Dam.ExecuteQuery(sql);
            sql = "CREATE TABLE fpAssociatedPageCategories (" +
                  "[CategoryID] INTEGER NOT NULL CONSTRAINT FK_fpAssociatedPageCategories_CategoryID REFERENCES fpPageCategories (ID), " +
                  "[PageID] INTEGER NOT NULL CONSTRAINT FK_fpAssociatedPageCategories_PageID REFERENCES fpPages (ID), " +
                  "CONSTRAINT PK_fpAssociatedPageCategories PRIMARY KEY (CategoryID, PageID)" +
                  ")";
            Dam.ExecuteQuery(sql);
            sql = "CREATE TABLE [fpAssociatedFolderPageCategories] (" +
                  "[CategoryID] INTEGER NOT NULL CONSTRAINT FK_fpAssociatedPageFolderCategories_CategoryID REFERENCES fpPageCategories (ID), " +
                  "[FolderID] INTEGER NOT NULL CONSTRAINT FK_fpAssociatedPageFolderCategories_FolderID REFERENCES fpFolders (ID), " +
                  "CONSTRAINT PK_fpAssociatedPageFolderCategories PRIMARY KEY (CategoryID, FolderID)" +
                  ")";
            Dam.ExecuteQuery(sql);
        }

        public override void Patch_0_7_10172_93()
        {
            string sql = "ALTER TABLE fpApplications ADD COLUMN [Description] MEMO NULL";
            Dam.ExecuteQuery(sql);
        }
    }
}